package gdrObject;

import java.io.File;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.ImageIcon;


public class GdrObject implements Serializable {

	public GdrObject(String name, String iconPath){
        this.name = name;
        this.iconPath = iconPath;
    }

    public String getName(){
        return name;
    }
    
    public String getIconPath(){
        return iconPath;
    }

    public ImageIcon getIcon(){
        return new ImageIcon(iconPath);
    }

    @Override
    public boolean equals(Object o){
        if(o instanceof GdrObject){
            GdrObject obj = (GdrObject)o;
            if(obj.getName().equalsIgnoreCase(name)){
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 79 * hash + (this.iconPath != null ? this.iconPath.hashCode() : 0);
        return hash;
    }
    
    public String toString(){
    	return getName();
    }
    
    public String toHTML(){
    	String img=null;
    	if(getIconPath() != null){
    		try {
				img = "<img src='" + new File(getIconPath()).toURI().toURL() + "' width=150 height=150> ";
			} catch (MalformedURLException e) {
				e.printStackTrace();
			}
    	}else{
    		img = "No image";
    	}
    	final String html =
    			"<html><body>"+
    	    	"<p align=\"center\">" + 
    	        img+"<br>"+
    	        "<h3>"+getName()+"</h3></p>"+
    	        "</body></html>";
    	return html;
    }

    private String name;
    private String iconPath;
    private static final long serialVersionUID = 641401072265552410L;
}
